<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>双色球摇奖</title>
    <script>
      function getNums() {
        //初始化奖池
        let balls = []
        for (let i = 0; i < 33; i++) {
          balls[i] = i + 1
        }
        let result = []
        let resultIdx = 0
        //循环抽取6次
        for (let i = 0; i < 6; ) {
          //随机下标
          let randomIdx = Math.floor(Math.random() * 33)
          if (balls[randomIdx] == 0) {
            //说明之前被抽到过
            continue
          } else {
            result[resultIdx++] = balls[randomIdx]
            //标记抽取元素,下次只要取到0就表示抽过的球
            balls[randomIdx] = 0
            //只有抽取到没抽取过的元素,次数才+1
            i++
          }
        }
        return result
      }
    </script>
  </head>
  <body></body>
</html>
